<?php

namespace app\applet\controller;

use app\applet\BaseController;

class ActivityEnlistController extends BaseController
{

    /**
     * 活动报名
     * @return \think\response\Json
     */
    public function addAction()
    {
        try{
            if(empty($this->post)){
                throw new \Exception("没有数据提交，不能处理",500);
            }

            $result = $this->app->activityService->checkSignup($this->post['activityId'],$this->post['userId']);

            if (!$result) {
                $this->app->activityEnlistService->add($this->post);
            }

            return json(['code' => 200, 'msg' => '添加成功', 'data'=> []]);
        }catch(\Exception $e){
            return json(['code' => $e->getCode(), 'msg' => $e->getMessage(), 'data'=> []]);
        }
    }
}